package collection;import java.util.LinkedList;/** * @Author: Beating Pupils * @Date: 2020/7/16 15:31 * @Description: 快速失败 */public class FastFailTest {    public static void main(String[] args) {        LinkedList<Integer> list = new LinkedList<>(); //linkedList也会有快速失败：currentModificationException//        List<Integer> list = new ArrayList<>();        list.add(2);        list.add(5);        list.add(0);        list.add(3);        //fast-fail示例        list.forEach(e -> {            System.out.println("当前元素是：" + list.indexOf(e) + " " + e);            list.remove(1);        });        //利用iterator不会出现fast-fail//        Iterator<Integer> iterator = list.iterator();//        while (iterator.hasNext()) {//            Integer next = iterator.next();//            if (next==5){//                iterator.remove();//            }//        }        System.out.println(111);    }}